<#import "../tpl/pageTep.ftl" as page>
    <@page.pageBase currentMenu="活动管理">

    <!--suppress ALL -->
    <form id="searchForm" class="form-panel" action="${basepath}/rest/manage/activity/selectActivityPage">
        <ul class="panel-content">
            <li>
                <div class="control-group span5" style="  line-height: 54px;">
                    <div class="search-controls  controls">
                        <input type="text" name="name" id="name" value="" placeholder="搜索关键字" class="bui-form-field" aria-disabled="false" aria-pressed="false">
                    </div>
                </div>
                <div class="form-actions span2">
                    <button type="submit" class="button  button-primary">
                        搜索
                    </button>
                </div>
                <div class="form-actions span6">
                    <a class="button button-danger" href="javascript:delFunction()">批量删除</a>
                    <a class="button button-success" href="${basepath}/rest/manage/activity/toAdd" style="margin-right: 40px;">新增活动</a>
                </div>
            </li>
        </ul>
    </form>
    <div id="grid"></div>
<script>
var Grid = BUI.Grid,
        Store = BUI.Data.Store,
        columns = [
            {title: '序号', dataIndex: 'id', elCls: 'center', width: '5%'},
            {title : '活动名称',dataIndex :'name',  elCls: 'center', width:'11%'},
            {title : '活动开始日期',dataIndex :'startDate',  elCls: 'center', width:'11%'},
            {title : '活动门店',dataIndex :'storeName',  elCls: 'center', width:'11%'},
            {title : '报名费用',dataIndex :'charge',  elCls: 'center', width:'11%'},
            {title : '报名人数',dataIndex :'amount', elCls: 'center', width:'11%',renderer:function(value,data){
                return '<a href="${basepath}/rest/manage/activity/toActivityJoin?id=' + data.id + '">' + value + '</a>';
}},
            {title : '照片墙审核',dataIndex :'id',  elCls: 'center',width:'11%', renderer:function (value) {
                    return '<a href="${basepath}/rest/manage/activity/toActivityPicture?id='+value+'">查看</a>';
                }},
            {title : '活动状态',dataIndex :'status',  elCls: 'center', width:'11%',renderer:function (value) {
                    value=value==1?'未开始':value==2?'进行中':'已结束';
                    return '<div>'+value+'</div>';
                }},
            {title : '操作',dataIndex : 'id',width:'18%', elCls: 'center', renderer : function (value,obj,index) {
                    var option1 = '<a href="${basepath}/rest/manage/activitypicture/toAdd?id=' + value + '">上传图片</a>';
                    var option2 = '<a href="${basepath}/rest/manage/activity/toEdit?id=' + value + '">编辑</a>';
                    var option3 = '<a href="javascript:deleteOne(' + value + ')">删除</a>';
                    return option1 + "&nbsp;&nbsp;&nbsp;&nbsp;" + option2+ "&nbsp;&nbsp;&nbsp;&nbsp;" + option3;
                }
            }
        ];

  //分页查询
var store = new Store({
            url: '/rest/manage/activity/selectActivityPage',
            autoLoad: true, //自动加载数据
            params: { //配置初始请求的参数
                length: '10'
            },
            pageSize: 10,	// 配置分页数目
            root: 'list',
            totalProperty: 'total'
        }),
  grid = new Grid.Grid({
            render:'#grid',
            columns : columns,
            loadMask: true, //加载数据时显示屏蔽层
            store: store,
            plugins : [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
            // 底部工具栏
            bbar:{
                pagingBar:true
            }
        });

grid.render();
/*--------------------------------模糊查询---------------------------------------------*/
var form = new BUI.Form.HForm({
    srcNode: '#searchForm'
}).render();

form.on('beforesubmit', function (ev) {
    //序列化成对象
    var obj = form.serializeToObject();
    obj.start = 0; //返回第一页
    store.load(obj);
    return false;
});
//删除单个
function deleteOne(id) {
    BUI.Message.Confirm('确认要删除吗？', function () {   //双选框
        $.ajax({
            type: "POST",                                //传输方法
            url: "${basepath}/rest/manage/activity/deleteJson",  //删除
            dataType: "json",                            //数据类型
            data: {
                id: id                                //向后端传的数据
            },
            success: function (data) {
                var obj = form.serializeToObject();      //将表单格式化成键值对形式
                obj.start = 0;                          //返回第一页
                store.load(obj);
            }
        });
    },'question')
}

//删除选中的记录
function delFunction(){
    var selections = grid.getSelection();
    var ids=new Array();
    for(var i=0;i<selections.length;i++){
        ids[i]=selections[i].id.toString()
    }
    $.ajax({
        type: "POST",
        url: "${basepath}/rest/manage/activity/deletesJson",
        dataType: "json",
        data: {
            ids:ids
        },
        success: function (data) {
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
        }
    });

}
</script>

</@page.pageBase>
